package cj.web.cc.controllers;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import cj.utils.Constants;
import cj.utils.DateUtils;
import cj.utils.MD5Security;
import cj.utils.Page;
import cj.utils.ReturnUUID;
import cj.web.cc.dao.ApplyDAO;
import cj.web.constants.GameAreaEnum;
import cj.web.constants.GameTypeEnum;
import cj.web.constants.MemuEnum;
import cj.web.constants.OrderSourceEnum;
import cj.web.constants.PayStatusEnum;
import cj.web.constants.PayWayEnum;
import cj.web.constants.PermitStatusEnum;
import cj.web.constants.WXPayAttachEnum;
import cj.web.game.dao.GameDAO;
import cj.web.pay.alipay.util.PriceFormat;
import cj.web.pay.weixin.UnifiedOrder;

@Path("apply")
public class ApplyController extends BaseController{
	@Autowired
	private ApplyDAO applyDao;
	@Autowired
	private GameDAO gameDao;
	
	/**
	 * 参赛证验证页面
	 * @param model
	 * @param gameId
	 * @return
	 */
	@Get("validatePage")
	public String validatePage(Model model, @Param("gameId")int gameId){
		
		List<Map> games = applyDao.getGameById(gameId);
		if(games != null && games.size() > 0 ){
			Map game = games.get(0);
			String price = PriceFormat.formatPrice(game.get("price"));
			String duration = game.get("duration").toString();
			String gameType = game.get("type").toString();
			String name = game.get("name").toString();
			String img = game.get("img").toString();
			
			model.add("img", img);
			model.add("name", name);
			model.add("price", price);
			model.add("duration", duration);
			model.add("gameType", gameType);
		}
		
		model.add("gameId", gameId);
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		
		return "/views/apply/apply.vm";
	}
	
	/**
	 * 验证方法
	 * @param gameId
	 * @param code
	 * @param pwd
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Post("validate")
	public String validate(@Param("gameId")int gameId, @Param("code")String code, 
			@Param("pwd")String pwd,HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		String memberId = getCookieValueByName(request, "memberId");
		//验证活动和帐号最大报名次数
		List<Map> games = applyDao.getGameById(gameId);
		if(games != null && games.size() > 0){
			
			String endDate = games.get(0).get("endDate").toString();
			int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
			if(flag<0){
				//活动结束
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_6);
				return "@" + jo.toString();
			}
			
			String startDate = games.get(0).get("startDate").toString();
			int flagstartDate = DateUtils.compareDateWithNow(DateUtils.parse(startDate));//与活动时间比较是否结束
			if(flagstartDate>0){
				//未开始
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_8);
				return "@" + jo.toString();
			}
			
			int maxApplyCount = Integer.parseInt(games.get(0).get("maxApplyCount").toString());//最大参赛人数
			
			List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId);
			if(maxApplyCount<=orderlis.size()){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_5);
				return "@" + jo.toString();
			}
			
		}
		
		//验证参赛证号密码帐号和状态
		pwd = MD5Security.md5(pwd);
		List<Map> objs = applyDao.validate(gameId, code);
		if(objs != null && objs.size() > 0){
			//存在参赛证号
			if(pwd.equals(objs.get(0).get("pwd").toString())){
				//密码正确
				int status = Integer.parseInt(objs.get(0).get("status").toString());//状态
				if(PermitStatusEnum.YXYSY.getValue()==status){
					//有效已使用
					
					List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId, code);//是否本人报名
					if(orderlis!=null && orderlis.size()>0){
						//是本人报名
						jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
						jo.put("returnCode", Constants.returnObj.returnCode.code_1);
						return "@" + jo.toString();
					}else{
						//不是本人报名
						jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
						jo.put("returnCode", Constants.returnObj.returnCode.code_3);
						return "@" + jo.toString();
					}
					
				}else if(PermitStatusEnum.YXWSY.getValue()==status){
					//有效未使用
					jo.put("returnFlag", Constants.returnObj.returnFlag_true);
					int permitId = Integer.parseInt(objs.get(0).get("id").toString());
					jo.put("permitId", permitId);
				}
			}else{
				//密码不正确
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_4);
			}
		}
		else{
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
			jo.put("returnCode", Constants.returnObj.returnCode.code_2);
		}
		
		request.getSession().setAttribute("token", pwd);
		
		return "@" + jo.toString();
	}
	
	/**
	 * 参赛详情
	 * @param model
	 * @param permitId
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@Get("infor")
	public String infor(Model model, @Param("permitId") int permitId, HttpServletRequest request) throws UnsupportedEncodingException{
		List<Map> grades = applyDao.asGradeEnum();
		model.add("Grade",grades);
//		List<Map> areas = applyDao.asAreaEnum();
		model.add("Area", EnumSet.allOf(GameAreaEnum.class));
		model.add("phone", getCookieValueByName(request, "phone"));
		
		List<Map> permits = applyDao.getPermitById(permitId);
		if( permits != null && permits.size() > 0 ){
			Map permit = permits.get(0);
			int gameId = Integer.parseInt(permit.get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String price = PriceFormat.formatPrice(game.get("price"));
				String duration = game.get("duration").toString();
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				permit.put("img", img);
				permit.put("price", price);
				permit.put("duration", duration);
				permit.put("gameType", gameType);
			}
			String areaName = permit.get("areaName").toString();
			permit.put("areaName", beginSubStr(areaName, "("));
			String schoolName = permit.get("schoolName").toString();
			permit.put("schoolName", beginSubStr(schoolName, "("));
			
			model.add("Permit",permit);
			
			//----------判断cookice是否存在paramsFillForm
			String paramsFillForm = getCookieValueByName(request, "paramsFillForm");
			if("".equals(paramsFillForm)){
				//添加存在信息---第一次
				model = returnExistInfor(model, request);
			}else{
				//添加cookice存在信息---第二次
				model = returnParamsForm(model, request, paramsFillForm);
			}
		}
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		return "/views/apply/fillForm.vm";
	}
	
	/**
	 * 如果cookice是否存在paramsFillForm
	 * @param model
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	private Model returnParamsForm(Model model,HttpServletRequest request,String paramsFillForm) throws UnsupportedEncodingException{
		//学生姓名@身份证号@学生就读区域@学生就读学校@学生就读年级@教导老师@父母名称@父母电话
		String params[] = paramsFillForm.split("@");
		
		try{
			model.add("name",URLDecoder.decode(params[0],"utf-8"));//学生姓名
			model.add("identityCard",URLDecoder.decode(params[1],"utf-8"));//身份证号
			model.add("areaId",URLDecoder.decode(params[2],"utf-8"));//学生就读区域
			model.add("school",URLDecoder.decode(params[3],"utf-8"));//学生就读学校
			model.add("gradeId",URLDecoder.decode(params[4],"utf-8"));//学生就读年级
			model.add("teacher",URLDecoder.decode(params[5],"utf-8"));//教导老师
			model.add("parentName",URLDecoder.decode(params[6],"utf-8"));//父母名称
			model.add("parentPhone",URLDecoder.decode(params[7],"utf-8"));//父母电话
			
			model.add("namefirst",URLDecoder.decode(params[0],"utf-8"));//学生姓名
			model.add("identityCardfirst",URLDecoder.decode(params[1],"utf-8"));//身份证号
			model.add("areaIdfirst",URLDecoder.decode(params[2],"utf-8"));//学生就读区域
			model.add("schoolfirst",URLDecoder.decode(params[3],"utf-8"));//学生就读学校
			model.add("gradeIdfirst",URLDecoder.decode(params[4],"utf-8"));//学生就读年级
			model.add("teacherfirst",URLDecoder.decode(params[5],"utf-8"));//教导老师
			model.add("parentNamefirst",URLDecoder.decode(params[6],"utf-8"));//父母名称
			model.add("parentPhonefirst",URLDecoder.decode(params[7],"utf-8"));//父母电话
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			model.add("name","");//学生姓名
			model.add("identityCard","");//身份证号
			model.add("areaId","");//学生就读区域
			model.add("school","");//学生就读学校
			model.add("gradeId","");//学生就读年级
			model.add("teacher","");//教导老师
			model.add("parentName","");//父母名称
			model.add("parentPhone","");//父母电话
			
			model.add("namefirst","");//学生姓名
			model.add("identityCardfirst","");//身份证号
			model.add("areaIdfirst","");//学生就读区域
			model.add("schoolfirst","");//学生就读学校
			model.add("gradeIdfirst","");//学生就读年级
			model.add("teacherfirst","");//教导老师
			model.add("parentNamefirst","");//父母名称
			model.add("parentPhonefirst","");//父母电话
		}
		
		return model;
	}
	
	/**
	 * 如果存在则返回存在信息
	 * @param model
	 * @param request
	 * @return
	 */
	private Model returnExistInfor(Model model,HttpServletRequest request){
		
		String memberId = getCookieValueByName(request, "memberId");
		List<Map> inforlis = applyDao.getOrderByUserId(Integer.parseInt(memberId));
		
		if(inforlis!=null && inforlis.size()>0){
			Map infor = inforlis.get(0);
			model.add("namefirst",infor.get("name"));//学生姓名
			model.add("identityCardfirst",infor.get("identityCard"));//身份证号
			model.add("areaIdfirst",infor.get("area"));//学生就读区域
			model.add("schoolfirst",infor.get("school"));//学生就读学校
			model.add("gradeIdfirst",infor.get("grade"));//学生就读年级
			model.add("teacherfirst",infor.get("teacher"));//教导老师
			model.add("parentNamefirst",infor.get("parentName"));//父母名称
			model.add("parentPhonefirst",infor.get("parentPhone"));//父母电话
		}
		else{
			model.add("namefirst","");//学生姓名
			model.add("identityCardfirst","");//身份证号
			model.add("areaIdfirst","");//学生就读区域
			model.add("schoolfirst","");//学生就读学校
			model.add("gradeIdfirst","");//学生就读年级
			model.add("teacherfirst","");//教导老师
			model.add("parentNamefirst","");//父母名称
			model.add("parentPhonefirst","");//父母电话
		}
		
		return model;
	}
	
	/**
	 * 确认订单
	 * @param gameId		活动ID
	 * @param gameType		活动类型
	 * @param duration		活动时间范围
	 * @param permitId		参赛证号ID
	 * @param areaName		参赛区域名
	 * @param schoolName	参赛学校名
	 * @param address		参赛地址
	 * @param code			参赛证号
	 * @param price			参赛价格
	 * @param parentName	父母名称
	 * @param parentPhone	父母电话
	 * @param name			报名名称
	 * @param identityCard	身份证号
	 * @param school		学校
	 * @param grade			年级
	 * @param area			区域
	 * @param teacher		指导老师
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@Post("confirmInfor")
	public String confirmInfor(Model model,@Param("gameId")int gameId,@Param("gameType")int gameType,@Param("duration")String duration, 
			@Param("permitId")int permitId,@Param("areaName")String areaName,@Param("schoolName")String schoolName,
			@Param("address")String address,@Param("code")String code,@Param("returnCode")String returnCode,
			@Param("price")String price,@Param("parentName")String parentName,@Param("parentPhone")String parentPhone, @Param("name")String name,
			@Param("identityCard")String identityCard,@Param("school")String school, @Param("grade")String grade,
			@Param("area")String area,@Param("teacher")String teacher,@Param("img")String img,
			HttpServletRequest request,HttpServletResponse response) throws Exception{
		model.add("gameId", gameId);
		model.add("gameType", gameType);
		model.add("duration", duration);
		model.add("permitId", permitId);
		model.add("areaName", areaName);
		model.add("schoolName", schoolName);
		model.add("address", address);
		model.add("code", code);
		model.add("returnCode", returnCode);
		model.add("price", price);
		model.add("parentName", parentName);
		model.add("parentPhone", parentPhone);
		model.add("name", name);
		model.add("identityCard", identityCard);
		model.add("school", school);
		model.add("grade", grade);
		model.add("area", area);
		model.add("teacher", teacher);
		model.add("img", img);
		
		if(request.getHeader("user-agent").toLowerCase().indexOf("micromessenger") != -1){ //微信浏览器
			model.add("payWay", PayWayEnum.WX.getValue());
			model.add("source", OrderSourceEnum.WX.getValue());
			Map<String, String> config = getConfigSign(request);
			model.add("Config", config);
		}
		else{  //网站
			model.add("payWay", PayWayEnum.ZFB.getValue());
			model.add("source", OrderSourceEnum.WZ.getValue());
		}
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		
		//学生姓名@身份证号@学生就读区域@学生就读学校@学生就读年级@教导老师@父母名称@父母电话
		
		String encode_name = URLEncoder.encode(name, "utf-8");
		String encode_identityCard = URLEncoder.encode(identityCard, "utf-8");
		String encode_area = URLEncoder.encode(area, "utf-8");
		String encode_school = URLEncoder.encode(school, "utf-8");
		String encode_grade = URLEncoder.encode(grade, "utf-8");
		String encode_teacher = URLEncoder.encode(teacher, "utf-8");
		String encode_parentName = URLEncoder.encode(parentName, "utf-8");
		String encode_parentPhone = URLEncoder.encode(parentPhone, "utf-8");
		
		setCookie(response, "paramsFillForm", encode_name+"@"+encode_identityCard
				+"@"+encode_area+"@"+encode_school+"@"+encode_grade
				+"@"+encode_teacher+"@"+encode_parentName+"@"+encode_parentPhone);
		
		return "/views/apply/confirmForm.vm";
	}
	
	/**
	 * 检查活动订单填入信息
	 * @param gameId
	 * @param permitId
	 * @param parentName
	 * @param parentPhone
	 * @param name
	 * @param identityCard
	 * @param school
	 * @param grade
	 * @param payWay
	 * @param source
	 * @param area
	 * @param teacher
	 * @param inputCode
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Post("checkOrder")
	public String checkOrder(@Param("gameId")int gameId, @Param("permitId")int permitId,
			@Param("identityCard")String identityCard,@Param("code")String inputCode,HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		String memberId = getCookieValueByName(request, "memberId");
		String phone = getCookieValueByName(request, "phone");
		//验证活动和帐号最大报名次数
		List<Map> games = applyDao.getGameById(gameId);
		if(games != null && games.size() > 0){
			
			String endDate = games.get(0).get("endDate").toString();
			int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
			if(flag<0){
				//活动结束
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_6);
			}
			
			int maxApplyCount = Integer.parseInt(games.get(0).get("maxApplyCount").toString());//最大参赛人数
			
			List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId);
			if(maxApplyCount<=orderlis.size()){
				jo.put("maxApplyCount", maxApplyCount);
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_5);
				return "@" + jo.toString();
			}
		}
		
		//验证考生身份信息
		List<Map> appliedOrders = applyDao.getOrderByIDCard(identityCard, gameId);
		if( appliedOrders != null && appliedOrders.size() > 0 ){                 //该身份证已报名
			Map appliedOrder = appliedOrders.get(0);
			int status = Integer.parseInt(appliedOrder.get("status").toString());
			if( status == PayStatusEnum.WFK.getValue() ){
				String createUser = appliedOrder.get("createUser").toString();
				if(createUser.equals(phone)){ //该身份证已报名,未付费,请前往我的个人中心>我的报名支付
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);   
					jo.put("returnCode", Constants.returnObj.returnCode.code_1);
					return "@" + jo.toString();
				}
				else{                         //该身份证已报名,未付费,请前往createUser的个人中心>我的报名支付
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);   
					jo.put("returnCode", Constants.returnObj.returnCode.code_8);
					return "@" + jo.toString();
				}
				
			}
			else if ( status == PayStatusEnum.YFK.getValue() ){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //该身份证已付费,已报名,不要重复报名
				jo.put("returnCode", Constants.returnObj.returnCode.code_2);
				return "@" + jo.toString();
			}
		}
		
		//验证参赛证号是否已使用
		List<Map> permits = applyDao.getValidatePermitById(permitId);   
		if( permits != null && permits.size() > 0 ){
			Map permit = permits.get(0);
			
			String pwdInDB = permit.get("pwd").toString();
			Object pwd = request.getSession().getAttribute("token");
			//验证参赛证号密码正确性
			if( pwd != null && !"".equals(pwd.toString())){
				if(!pwd.toString().equals(pwdInDB)){
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase); 
					jo.put("returnCode", Constants.returnObj.returnCode.code_4);//准考证密码不正确
					return "@" + jo.toString();
				}
			}
			else{
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); 
				jo.put("returnCode", Constants.returnObj.returnCode.code_4);//准考证密码不正确
				return "@" + jo.toString();
			}
		}
		else{
			List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId, inputCode);//是否本用户使用
			if(orderlis!=null && orderlis.size()>0){
				//是本用户使用
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_7);
			}else{
				//不是本用户使用
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_3);
			}
			
			return "@" + jo.toString();
		}
		
		return "@" + jo.toString();
	}
	
	/**
	 * 去支付-生成订单
	 * @param gameId
	 * @param duration
	 * @param permitId
	 * @param areaName
	 * @param schoolName
	 * @param address
	 * @param code
	 * @param returnCode
	 * @param price
	 * @param parentName
	 * @param parentPhone
	 * @param name
	 * @param identityCard
	 * @param school
	 * @param grade
	 * @param payWay
	 * @param source
	 * @param area
	 * @param teacher
	 * @param request
	 * @return
	 * @throws Exception 
	 */
	@Post("createOrder")
	public synchronized String createOrder(@Param("gameId")int gameId, @Param("permitId")int permitId,
			@Param("parentName")String parentName,@Param("parentPhone")String parentPhone, @Param("name")String name,
			@Param("identityCard")String identityCard,@Param("school")String school, @Param("grade")String grade,
			@Param("payWay")int payWay,@Param("source")int source,@Param("area")String area,@Param("teacher")String teacher,@Param("code")String inputCode,
			HttpServletRequest request,HttpServletResponse response) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		String price = "",
				duration = "",
				gameType = "";
		String memberId = getCookieValueByName(request, "memberId");
		String phone = getCookieValueByName(request, "phone");
		//验证活动和帐号最大报名次数
		List<Map> games = applyDao.getGameById(gameId);
		if(games != null && games.size() > 0){
			
			String endDate = games.get(0).get("endDate").toString();
			int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
			if(flag<0){
				//活动结束
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_6);
			}
			
			int maxApplyCount = Integer.parseInt(games.get(0).get("maxApplyCount").toString());//最大参赛人数
			
			List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId);
			if(maxApplyCount<=orderlis.size()){
				jo.put("maxApplyCount", maxApplyCount);
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_5);
				return "@" + jo.toString();
			}
			
			price = games.get(0).get("price").toString();
			duration = games.get(0).get("duration").toString();
			gameType = games.get(0).get("type").toString();
		}
		
		//验证考生身份信息
		List<Map> appliedOrders = applyDao.getOrderByIDCard(identityCard, gameId);
		if( appliedOrders != null && appliedOrders.size() > 0 ){                 //该身份证已报名
			Map appliedOrder = appliedOrders.get(0);
			int status = Integer.parseInt(appliedOrder.get("status").toString());
			if( status == PayStatusEnum.WFK.getValue() ){
				String createUser = appliedOrder.get("createUser").toString();
				if(createUser.equals(phone)){ //该身份证已报名,未付费,请前往我的个人中心>我的报名支付
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);   
					jo.put("returnCode", Constants.returnObj.returnCode.code_1);
					return "@" + jo.toString();
				}
				else{                         //该身份证已报名,未付费,请前往createUser的个人中心>我的报名支付
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);   
					jo.put("returnCode", Constants.returnObj.returnCode.code_8);
					return "@" + jo.toString();
				}
				
			}
			else if ( status == PayStatusEnum.YFK.getValue() ){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //该身份证已付费,已报名,不要重复报名
				jo.put("returnCode", Constants.returnObj.returnCode.code_2);
				return "@" + jo.toString();
			}
		}
		
		//验证参赛证号是否已使用
		String orderNo = "",
				code = "",
				returnCode = "",
				areaName = "",
				schoolName="",
				address="";
		List<Map> permits = applyDao.getValidatePermitById(permitId);   
		if( permits != null && permits.size() > 0 ){
			Map permit = permits.get(0);
			
			String pwdInDB = permit.get("pwd").toString();
			Object pwd = request.getSession().getAttribute("token");
			//验证参赛证号密码正确性
			if( pwd != null && !"".equals(pwd.toString())){
				if(!pwd.toString().equals(pwdInDB)){
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase); 
					jo.put("returnCode", Constants.returnObj.returnCode.code_4);//准考证密码不正确
					return "@" + jo.toString();
				}
			}
			else{
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); 
				jo.put("returnCode", Constants.returnObj.returnCode.code_4);//准考证密码不正确
				return "@" + jo.toString();
			}
			code = permit.get("code").toString();
			orderNo = ReturnUUID.getOrderNo(code);
			returnCode = permit.get("returnCode").toString();
			areaName = beginSubStr(permit.get("areaName").toString(), "(");
			schoolName = beginSubStr(permit.get("schoolName").toString(), "(");
			address = permit.get("address").toString();
			
			int status = PayStatusEnum.WFK.getValue();
			
			if( gameType.equals(GameTypeEnum.MF.getValue()) ){ //免费活动
				status = PayStatusEnum.YFK.getValue();
			}
			
			int orderId = applyDao.createOrder(orderNo, memberId, gameId, duration, permitId, areaName, schoolName, address, code, returnCode, 
					price, parentName, parentPhone, name, identityCard, school, grade, source, status, phone, area, teacher);
			
			applyDao.changeStatusById(permitId, PermitStatusEnum.YXYSY.getValue(), phone);  //改准考证状态为已使用
			jo.put("orderId", orderId);
		}
		else{
			List<Map> orderlis = applyDao.getOrderByUserId(Integer.parseInt(memberId), gameId, inputCode);//是否本用户使用
			if(orderlis!=null && orderlis.size()>0){
				//是本用户使用
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_7);
			}else{
				//不是本用户使用
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
				jo.put("returnCode", Constants.returnObj.returnCode.code_3);
			}
			
			return "@" + jo.toString();
		}
		
		//支付
		if( gameType.equals(GameTypeEnum.FF.getValue()) ){ //付费活动
			if( payWay == PayWayEnum.ZFB.getValue() ){     //支付宝支付
				
			}
			else if( payWay == PayWayEnum.WX.getValue() ){ //微信支付
				//调用微信接口
				String tmpPrice = String.valueOf(Float.parseFloat(price) * 100);
				String total_fee = tmpPrice.substring(0, tmpPrice.indexOf("."));
				String spbill_create_ip = request.getRemoteAddr();
				String notify_url = request.getScheme() +"://" + request.getServerName() + "/wxNotify/result";
		        String openId = getCookieValueByName(request, "openId");
		        if(openId != null && openId.length() > 0){
		        	jo.put("hasOpenId", true);
		        	UnifiedOrder unifiedOrder = new UnifiedOrder();
		    		Map prepay = unifiedOrder.getPrepayId("确认订单-我的报名", orderNo, total_fee, spbill_create_ip, notify_url, openId ,WXPayAttachEnum.BM.getValue());
		    		jo.put("rtn", prepay);
		        }
		        else{
		        	jo.put("hasOpenId", false);
		        }
			}
		}
		
		//支付成功移除cookice中paramsFillForm
		removeCookie(response, "paramsFillForm");
		
		return "@" + jo.toString();
	}
	
	private String beginSubStr(String pattern, String endString){
		int endIndex = pattern.indexOf(endString);
		if(endIndex >= 0){
			pattern = pattern.substring(0,endIndex);
		}
		
		return pattern;
	}
	
	//----------我的报名

	/**
	 * 修改考生信息
	 * @param model
	 * @param orderId
	 * @return
	 */
	@Get("upFormPage")
	public String upFormPage(Model model, @Param("orderId") int orderId){
		List<Map> grades = applyDao.asGradeEnum();
		model.add("Grade",grades);
		List<Map> areas = applyDao.asAreaEnum();
		model.add("Area", EnumSet.allOf(GameAreaEnum.class));
		
		List<Map> gameOrder = applyDao.getOrderById(orderId);
		if(gameOrder!=null && gameOrder.size()>0){
			int gameId = Integer.parseInt(gameOrder.get(0).get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String price = PriceFormat.formatPrice(game.get("price"));
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				model.add("img", img);
				model.add("price", price);
				model.add("gameType", gameType);
				model.add("obj", gameOrder.get(0));
				
				model.add("selArea", gameOrder.get(0).get("area").toString());
				
//				for(Map area : areas){
//					String areaName = area.get("name").toString();
//					if( gameOrder.get(0).get("area").toString().indexOf(areaName) >= 0){
//						model.add("selArea", areaName);
//						break;
//					}
//				}
				
				for(Map grade : grades){
					String gradeName = grade.get("name").toString();
					if( gameOrder.get(0).get("grade").toString().indexOf(gradeName) >= 0){
						model.add("selGrade", gradeName);
						break;
					}
				}
			}
		}
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		return "/views/apply/updateForm.vm";
	}
	
	/**
	 * 修改报名信息
	 * @param orderId
	 * @param name
	 * @param identityCard
	 * @param areaId
	 * @param school
	 * @param gradeId
	 * @param teacher
	 * @param parentName
	 * @param parentPhone
	 * @return
	 * @throws Exception
	 */
	@Post("upForm")
	public String upForm(@Param("orderId")int orderId,@Param("name")String name, @Param("identityCard")String identityCard, 
			@Param("area")String area, @Param("school")String school,@Param("grade")String grade,
			@Param("teacher")String teacher,@Param("parentName")String parentName,@Param("parentPhone")String parentPhone,
			HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		String phone = getCookieValueByName(request, "phone");
		try {
			List<Map> rep = applyDao.getOrderById(orderId);
			if(rep!=null && rep.size()>0){
				int status = Integer.parseInt(rep.get(0).get("status").toString());
				int gameId = Integer.parseInt(rep.get(0).get("gameId").toString());
				
				//身份证是不是已经使用=状态为已付款
				int count = applyDao.checkOrderByIdentityCard(identityCard, gameId, orderId);
				if(count>0){
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
					jo.put("returnCode", Constants.returnObj.returnCode.code_1);
					return "@" + jo.toString();
				}
				
				if(PayStatusEnum.WFK.getValue()==status){
					applyDao.updateOrder(orderId, name, identityCard, area, school, grade, teacher, parentName, parentPhone, phone);
				}else{
					
					applyDao.updateOrderForYFK(orderId, identityCard, area, school, grade, teacher, parentName, parentPhone, phone);
//					jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
//					jo.put("returnCode", Constants.returnObj.returnCode.code_3);
				}
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
		}
		
		return "@" + jo.toString();
	}
	
	/**
	 * 查看报名详情
	 * @param model
	 * @param orderId 活动订单id
	 * @return
	 * @throws Exception 
	 */
	@Get("dtFormPage")
	public String detailFormPage(Model model, @Param("orderId") int orderId, HttpServletRequest request) throws Exception{
		List<Map> gameOrder = applyDao.getOrderById(orderId);
		if(gameOrder!=null && gameOrder.size()>0){
			
			int gameId = Integer.parseInt(gameOrder.get(0).get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				String gameName = game.get("name").toString();
				model.add("img", img);
				model.add("gameType", gameType);
				model.add("gameName", gameName);
				model.add("obj", gameOrder.get(0));
				
				if(request.getHeader("user-agent").toLowerCase().indexOf("micromessenger") != -1){ //微信浏览器
					model.add("payWay", PayWayEnum.WX.getValue());
					Map<String, String> config = getConfigSign(request);
					model.add("Config", config);
				}
				else{  //普通浏览器
					model.add("payWay", PayWayEnum.ZFB.getValue());
				}
				
				//-------------与活动时间比较是否结束
				String endDate = game.get("endDate").toString();
				int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
				model.add("endAtflag", flag);
				//-------------
			}
		}
		
		//获奖信息--------------------------------
		boolean levelFlag=false;
		List<Map> reportCard = applyDao.queryByGameIdAndCode(Integer.parseInt(gameOrder.get(0).get("gameId").toString()), 
				gameOrder.get(0).get("code").toString());
		
		if(reportCard!=null && reportCard.size()>0){
			String level = reportCard.get(0).get("level")==null?"":reportCard.get(0).get("level").toString();
			if(level!=null && !"".equals(level)){
				model.add("levelFlag", true);
				model.add("level", level);
				model.add("path", reportCard.get(0).get("path")==null?"":reportCard.get(0).get("path").toString());
			}else{
				model.add("levelFlag", levelFlag);
				model.add("level", "无");
			}
		}else{
			model.add("levelFlag", levelFlag);
			model.add("level", "无");
		}
		
		//判断活动成绩是不是已经出来了
		int gameResultFlag = applyDao.queryByGameIdCount(Integer.parseInt(gameOrder.get(0).get("gameId").toString()));
		model.add("gameResultFlag", gameResultFlag);
		
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		return "/views/apply/detailForm.vm";
	}
	
	/**
	 * 报名列表
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@Get("myApplyPage")
	public String myApplyPage(Model model,HttpServletRequest request) throws Exception{
		if(request.getHeader("user-agent").toLowerCase().indexOf("micromessenger") != -1){ //微信浏览器
			model.add("payWay", PayWayEnum.WX.getValue());
			Map<String, String> config = getConfigSign(request);
			model.add("Config", config);
		}
		else{  //普通浏览器
			model.add("payWay", PayWayEnum.ZFB.getValue());
		}
		
		model.add("currentTopMemu", MemuEnum.memuhdbm);
		return "/views/uc/wx/applyList.vm";
	}
	
	
	//---------------PC-----------------
	/**
	 * pc版我的报名列表
	 * @param model
	 * @return
	 */
	@Get("pcApply")
	public String pcApply(Model model, HttpServletRequest request) {
		
		String phone = getCookieValueByName(request, "phone");
		model.add("phone", phone);
		model.add("currentMemu", MemuEnum.wdbm);
		model.add("currentTopMemu", MemuEnum.memugrzx);
		return "/views/uc/applyList.vm";
	}
	
	/**
	 * pc版我的报名列表分页
	 * @param start
	 * @param length
	 * @param request
	 * @return
	 * @throws ParseException 
	 */
	@Post("pcApplylis")
	public String pcApplylis(@Param("start") int start,@Param("length") int length, HttpServletRequest request) throws ParseException {
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		String memberId = getCookieValueByName(request, "memberId");
		
		List<Map> repsList = applyDao.getOrderByUserId(Integer.parseInt(memberId),start*length,length);
		
		for(Map rep:repsList){
			int gameId = Integer.parseInt(rep.get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				String gameName = game.get("name").toString();
				
				rep.put("img", img);
				rep.put("gameType", gameType);
				rep.put("gameName", gameName);
				rep.put("payAt", DateUtils.formatDateStr(rep.get("updateAt").toString(),DateUtils.DATE_FULL_STR));
				
				//获奖信息--------------------------------start
				boolean levelFlag=false;
				String code = rep.get("code").toString();
				List<Map> reportCard = applyDao.queryByGameIdAndCode(gameId, code);
				if(reportCard!=null && reportCard.size()>0){
					String level = reportCard.get(0).get("level")==null?"":reportCard.get(0).get("level").toString();
					if(level!=null && !"".equals(level)){
						rep.put("levelFlag", true);
						rep.put("level", level);
						rep.put("path", reportCard.get(0).get("path")==null?"":reportCard.get(0).get("path").toString());
					}else{
						rep.put("levelFlag", levelFlag);
						rep.put("level", "无");
					}
				}else{
					rep.put("levelFlag", levelFlag);
					rep.put("level", "无");
				}
				
				//判断活动成绩是不是已经出来了
				int gameResultFlag = applyDao.queryByGameIdCount(gameId);
				rep.put("gameResultFlag", gameResultFlag);
				
				//获奖信息--------------------------------end
				
				//-------------与活动时间比较是否结束
				String endDate = games.get(0).get("endDate").toString();
				int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
				rep.put("endAtflag", flag);
				//-------------
				
				//-------------判断回执码
				String returnCode = rep.get("returnCode").toString();
				
				if(returnCode.length()>8){
					rep.put("returnCodeFlag", "1");
					rep.put("returnCode", returnCode);
					rep.put("roomNo", returnCode.substring(4, 6));
					rep.put("seatNo", returnCode.substring(6, 9));
				}else{
					rep.put("returnCodeFlag", "0");
					rep.put("returnCode", returnCode);
				}
				//-------------
			}
		}
		
		int totalCount = applyDao.getOrderByUserIdSize(Integer.parseInt(memberId));
		
		//分页计算
		Page p= new Page<Map>(0, length, repsList, totalCount);
		jo.put("list", repsList);
		jo.put("repsize", p.getTotalPages());
		jo.put("totalCount", totalCount);
		return "@"+jo.toString();
	}
	
	/**
	 * 查看报名详情
	 * @param model
	 * @param orderId 活动订单id
	 * @return
	 * @throws Exception 
	 */
	@Get("dtPCFormPage")
	public String detailPCFormPage(Model model, @Param("orderId") int orderId, HttpServletRequest request) throws Exception{
		List<Map> gameOrder = applyDao.getOrderById(orderId);
		if(gameOrder!=null && gameOrder.size()>0){
			
			int gameId = Integer.parseInt(gameOrder.get(0).get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				String gameName = game.get("name").toString();
				model.add("img", img);
				model.add("gameType", gameType);
				model.add("gameName", gameName);
				model.add("createAt", DateUtils.formatDateStr(gameOrder.get(0).get("createAt").toString(),DateUtils.DATE_FULL_STR));
				model.add("payAt", DateUtils.formatDateStr(gameOrder.get(0).get("updateAt").toString(),DateUtils.DATE_FULL_STR));
				model.add("obj", gameOrder.get(0));
				
				//-------------与活动时间比较是否结束
				String endDate = games.get(0).get("endDate").toString();
				int flag = DateUtils.compareDateWithNow(DateUtils.parse(endDate));//与活动时间比较是否结束
				model.add("endAtflag", flag);
				//-------------
				
			}
		}
		
		//获奖信息--------------------------------
		boolean levelFlag=false;
		List<Map> reportCard = applyDao.queryByGameIdAndCode(Integer.parseInt(gameOrder.get(0).get("gameId").toString()), 
				gameOrder.get(0).get("code").toString());
		if(reportCard!=null && reportCard.size()>0){
			String level = reportCard.get(0).get("level")==null?"":reportCard.get(0).get("level").toString();
			if(level!=null && !"".equals(level)){
				model.add("levelFlag", true);
				model.add("level", level);
				model.add("path", reportCard.get(0).get("path")==null?"":reportCard.get(0).get("path").toString());
			}else{
				model.add("levelFlag", levelFlag);
				model.add("level", "无");
			}
		}else{
			model.add("levelFlag", levelFlag);
			model.add("level", "无");
		}
		
		//判断活动成绩是不是已经出来了
		int gameResultFlag = applyDao.queryByGameIdCount(Integer.parseInt(gameOrder.get(0).get("gameId").toString()));
		model.add("gameResultFlag", gameResultFlag);
		
		String phone = getCookieValueByName(request, "phone");
		model.add("phone", phone);
		model.add("currentMemu", MemuEnum.wdbm);
		model.add("currentTopMemu", MemuEnum.memugrzx);
		return "/views/uc/applyDetail.vm";
	}
	
	/**
	 * 修改考生信息
	 * @param model
	 * @param orderId
	 * @return
	 * @throws ParseException 
	 */
	@Get("upPCFormPage")
	public String upPCFormPage(Model model, @Param("orderId") int orderId, HttpServletRequest request) throws ParseException{
		List<Map> grades = applyDao.asGradeEnum();
		model.add("Grade",grades);
		List<Map> areas = applyDao.asAreaEnum();
		model.add("Area", EnumSet.allOf(GameAreaEnum.class));
		
		List<Map> gameOrder = applyDao.getOrderById(orderId);
		if(gameOrder!=null && gameOrder.size()>0){
			int gameId = Integer.parseInt(gameOrder.get(0).get("gameId").toString());
			List<Map> games = applyDao.getGameById(gameId);
			if(games != null && games.size() > 0 ){
				Map game = games.get(0);
				String price = PriceFormat.formatPrice(game.get("price"));
				String gameType = game.get("type").toString();
				String img = game.get("img").toString();
				model.add("img", img);
				model.add("price", price);
				model.add("gameType", gameType);
				model.add("createAt", DateUtils.formatDateStr(gameOrder.get(0).get("createAt").toString(),DateUtils.DATE_FULL_STR));
				model.add("obj", gameOrder.get(0));
				
				model.add("selArea", gameOrder.get(0).get("area").toString());
				
//				for(Map area : areas){
//					String areaName = area.get("name").toString();
//					if( gameOrder.get(0).get("area").toString().indexOf(areaName) >= 0){
//						model.add("selArea", areaName);
//						break;
//					}
//				}
				
				for(Map grade : grades){
					String gradeName = grade.get("name").toString();
					if( gameOrder.get(0).get("grade").toString().indexOf(gradeName) >= 0){
						model.add("selGrade", gradeName);
						break;
					}
				}
			}
		}
		
		String phone = getCookieValueByName(request, "phone");
		model.add("phone", phone);
		model.add("currentMemu", MemuEnum.wdbm);
		model.add("currentTopMemu", MemuEnum.memugrzx);
		return "/views/uc/modifyUser.vm";
	}
	
	@Post("wxpay")
	public String wxpay(@Param("orderId")int orderId, HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		String price = "",
				orderNo = "";
		List<Map> orders = applyDao.getOrderById(orderId);
		if( orders != null && orders.size() > 0 ){ //验证订单是否存在
			Map order = orders.get(0);
			int status = Integer.parseInt(order.get("status").toString());
			if( status == PayStatusEnum.YFK.getValue() ){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //是否已付款
				jo.put("returnCode", Constants.returnObj.returnCode.code_2);
				return "@" + jo.toString();
			}
			price = order.get("price").toString();
			orderNo = order.get("orderNo").toString();
		}
		else{
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
			jo.put("returnCode", Constants.returnObj.returnCode.code_1);
			return "@" + jo.toString();
		}
		
		//调用微信接口
		String tmpPrice = String.valueOf(Float.parseFloat(price) * 100);
		String total_fee = tmpPrice.substring(0, tmpPrice.indexOf("."));
		String spbill_create_ip = request.getRemoteAddr();
		String notify_url = request.getScheme() +"://" + request.getServerName() + "/wxNotify/result";
        String openId = getCookieValueByName(request, "openId");
        if(openId != null && openId.length() > 0){
        	jo.put("hasOpenId", true);
        	UnifiedOrder unifiedOrder = new UnifiedOrder();
    		Map prepay = unifiedOrder.getPrepayId("确认订单-我的报名", orderNo, total_fee, spbill_create_ip, notify_url, openId ,WXPayAttachEnum.BM.getValue());
    		jo.put("rtn", prepay);
        }
        else{
        	jo.put("hasOpenId", false);
        }
        
        return "@" + jo.toString();
	}
	
	@Post("alipay")
	public String alipay(@Param("orderId")int orderId, HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		List<Map> orders = applyDao.getOrderById(orderId);
		if( orders != null && orders.size() > 0 ){ //验证订单是否存在
			Map order = orders.get(0);
			int status = Integer.parseInt(order.get("status").toString());
			if( status == PayStatusEnum.YFK.getValue() ){
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //是否已付款
				jo.put("returnCode", Constants.returnObj.returnCode.code_2);
				return "@" + jo.toString();
			}
		}
		else{
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
			jo.put("returnCode", Constants.returnObj.returnCode.code_1);
			return "@" + jo.toString();
		}
		
		jo.put("orderId", orderId);
		return "@" + jo.toString();
	}
	
	/**
	 * 模糊匹配学校名称
	 * @param areaName
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Post("mathingSchool")
	public String mathingSchool(@Param("areaName")String areaName, HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		List<Map> reps = applyDao.queryTBSchoolName(areaName);
		jo.put("reps", reps);
		return "@" + jo.toString();
	}
	
	/**
	 * 取消订单
	 * @param orderId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Post("cancelOrder")
	public String cancelOrder(@Param("orderId")int orderId, HttpServletRequest request) throws Exception{
		JSONObject jo = new JSONObject();
		jo.put("returnFlag", Constants.returnObj.returnFlag_true);
		
		List<Map> orders = applyDao.getOrderById(orderId);
		//验证报名订单是否存在
		if( orders != null && orders.size() > 0 ){
			Map order = orders.get(0);
			int status = Integer.parseInt(order.get("status").toString());
			if( status == PayStatusEnum.YFK.getValue() ){
				//已付款
				jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //是否已付款
				jo.put("returnCode", Constants.returnObj.returnCode.code_3);
				return "@" + jo.toString();
			}else{
				int permitId = Integer.parseInt(order.get("permitId").toString());
				//参赛证信息
				List<Map> permitObj = applyDao.getPermitById(permitId);
				if( permitObj != null && permitObj.size() > 0 ){ //验证参赛证是否存在
					//作废订单
					applyDao.updateOrderStatusById(orderId, PayStatusEnum.ZF.getValue());
					//修改参赛证状态为未使用
					applyDao.changeStatusById(permitId, PermitStatusEnum.YXWSY.getValue(), order.get("createUser").toString());
				}else{
					jo.put("returnFlag", Constants.returnObj.returnFlag_flase); //是否已付款
					jo.put("returnCode", Constants.returnObj.returnCode.code_2);
					return "@" + jo.toString();
				}
			}
		}
		else{
			jo.put("returnFlag", Constants.returnObj.returnFlag_flase);
			jo.put("returnCode", Constants.returnObj.returnCode.code_2);
			return "@" + jo.toString();
		}
		
		return "@" + jo.toString();
	}
	
	/**
	 * 取消订单
	 * @param orderId
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@Get("successOrder")
	public String successOrder(Model model, @Param("orderId")int orderId, HttpServletRequest request) throws Exception{
		List<Map> orders = applyDao.getOrderById(orderId);
		model.add("orderId",orderId);
		if( orders != null && orders.size() > 0 ){
			Map order = orders.get(0);
			model.add("name",order.get("name").toString());
			model.add("schoolName",order.get("schoolName").toString());
			model.add("duration",order.get("duration").toString());
			model.add("code",order.get("code").toString());
			model.add("returnCode",order.get("returnCode").toString());
			if(request.getHeader("user-agent").toLowerCase().indexOf("micromessenger") != -1){ //微信浏览器
				model.add("payWay", PayWayEnum.WX.getValue());
			}
			else{  //网站
				model.add("payWay", PayWayEnum.ZFB.getValue());
			}
			return "/views/apply/paySuccess.vm";
		}
		else{
			return "/views/apply/payFail.vm";
		}
	}
}